package com.phone580.app.download;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.widget.ListView;

import com.phone580.app.BaseActivity;
import com.phone580.app.Constant;
import com.phone580.app.MainApplication;
import com.phone580.app.R;
import com.phone580.app.entity.DownloadInfoEntity;
import com.phone580.app.model.DownloadManagerModel;

public class FinishDownloadActivity extends BaseActivity {
	private DownloadManagerModel model;
	private ListView finishList;
	private FinishDownloadAdapter adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.finish_download_layout);
		model = new DownloadManagerModel(this);
		finishList = (ListView) findViewById(R.id.finish_download_list_lv);
		adapter = new FinishDownloadAdapter(this);
	}
	
	@Override
	protected void onStart() {
		super.onStart();
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		refresh();
	}
	
	public void refresh() {
		List<DownloadInfoEntity> data = model.getfinished();
//		List<DownloadInfoEntity> data = new ArrayList<DownloadInfoEntity>();
//		MainApplication app = (MainApplication) this.getApplication();
//		for (DownloadInfoEntity info : app.getDownloadList()) {
//			if (info.getStatus() == Constant.DOWNLOAD_FINISH) {
//				data.add(info);
//			}
//		}
		adapter.setData(data);
		finishList.setAdapter(adapter);
	}
	
	@Override
	public void onBackPressed() {
		pressAgainExit();
	}
}
